package com.wowudi.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wowudi.dto.ListDto;
import com.wowudi.entity.DoctorAdvice;
import com.wowudi.service.*;
import com.wowudi.util.MsgUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Array;
import java.util.Date;
import java.util.Random;

@RestController
@RequestMapping("api/pati/doct")
public class DoctController {
    @Autowired
    private DoctorAdviceService doctorAdviceService;
    @Autowired
    private TreatResultService treatResultService;
    @Autowired
    private DrugService drugService;
    @Autowired
    private DoctorAdviceItemsService doctorAdviceItemsService;
    @Autowired
    private PatientsService patientsService;
    @RequestMapping("findDoct")
    public Page<DoctorAdvice> findPati(Integer pageym , Integer pagesize,String cartid, String patiname) {
        Page<DoctorAdvice> page = new Page<DoctorAdvice>(pageym,pagesize);
        this.doctorAdviceService.page(page);
        // this.doctorAdviceService.getAllBynameandid(page,cartid,patiname);
        return page;
    }
    @RequestMapping("findDoct11")
    public Page<DoctorAdvice> findDoct(Integer pageym , Integer pagesize,String cartid, String patiname) {
        Page<DoctorAdvice> page = new Page<DoctorAdvice>(pageym,pagesize);
        // this.doctorAdviceService.page(page);
        this.doctorAdviceService.getAllBynameandid(page,cartid,patiname);
        return page;
    }
    //添加
    @RequestMapping("addDoct")
    public MsgUtil addPati(@RequestBody DoctorAdvice doctorAdvice) {
        doctorAdvice.setDIsdel(0);
        doctorAdvice.setDaCreateTime(new Date());
        System.out.println(doctorAdvice);
        Boolean bool=this.doctorAdviceService.save(doctorAdvice);
       // Integer bool=this.doctorAdviceService.addDoct(doctorAdvice,list);
        if (bool){
            return new MsgUtil(true,"添加成功",null);
        }else {
            return new MsgUtil(false,"添加失败",null);
        }
    }
    //删除
    @RequestMapping("delDoct")
    public MsgUtil delPati(Integer id) {
        DoctorAdvice doctorAdvice=this.doctorAdviceService.getById(id);
        doctorAdvice.setDIsdel(1);
        boolean bool=this.doctorAdviceService.updateById(doctorAdvice);
        if (bool){
            return new MsgUtil(true,"删除成功",null);
        }else {
            return new MsgUtil(false, "删除失败", null);
        }
    }
    @RequestMapping("getListDto")
    public ListDto getListDto() {
        ListDto listDto=new ListDto(null,null,null,this.patientsService.list(),this.drugService.list());
        return listDto;
    }
}
